package com.mce.nebula.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 统一API响应格式
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ApiResponse<T> {

    private Boolean ok = true;
    private String msg;
    @JsonProperty(value = "msg_show")
    private String msgShow;
    private Integer code = 200;
    private ResponseBean<T> data;
    
    public static <T> ApiResponse<T> success(T data) {
        return new ApiResponse<>(true, "success", "操作成功", 200, new ResponseBean<>(data,null));
    }
    
    public static <T> ApiResponse<T> success(T data, String message) {
        return new ApiResponse<>(true, "success", message, 200, new ResponseBean<>(data,null));
    }

    public static <T> ApiResponse<T> success(ResponseBean bean, String message) {
        return new ApiResponse<>(true, "success", message, 200, bean);
    }
    
    public static <T> ApiResponse<T> error(String message) {
        return new ApiResponse<>(false, "error", message, 400, null);
    }
    
    public static <T> ApiResponse<T> error(Integer code, String message) {
        return new ApiResponse<>(false, "error", message, code, null);
    }
    
    public static <T> ApiResponse<T> error(Integer code, String msg, String msgShow) {
        return new ApiResponse<>(false, msg, msgShow, code, null);
    }

    public record  ResponseBean<T>(Object bean, List<T> list){
    }
}





